<template>
  <div class="search">
    <f-form ref="form" :action="api.company" :form-key="this.formItem.companyId">
      <f-form-item label="所属机构" type="select" name="organizationId" :value="formItem.organizationId" :data="api.organization.list" valueKey="organizationId" label-key="organizationName" :required="true" v-if="this.superAdmin"/>
      <f-form-item label="企业名称" name="companyName" :required="true" :value="formItem.companyName"/>
      <f-form-item label="联系人" name="linkMan" :required="true" :value="formItem.linkMan"/>
      <f-form-item label="联系电话" name="linkTel" :required="true" :value="formItem.linkTel"/>
      <f-form-item label="所属区域" type="areaSelect" name="areaIds" :required="true"  :value="areaIds"  v-if="loaded"></f-form-item>
      <f-form-item label="企业地址" name="companyAddress"  :value="formItem.companyAddress"/>
      <f-form-item label="主营范围" name="businessScope" type="textarea" :value="formItem.businessScope"/>
      <f-form-item label="企业简介" name="companyDesc" type="editor" :value="formItem.companyDesc"/>
      <f-form-item label="企业Logo" type="upload" name="companyLogo" :value="formItem.companyLogo"  :file-max="1"/>
    </f-form>
  </div>
</template>

<script>

  export default {
    name: 'companyForm',
    props: {},
    data() {
      return {
        isAdd: true,
        areaIds: [],
        loaded: false,
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          companyName: '',
          linkTel: '',
          companyLogo:'',
          linkMan: '',
          companyAddress: '',
          auditState: 1,
          companyDesc: '',
          businessScope: ''

        }
      },
      setData(data) {
        this.$refs.form.resetFields()
        if (data && data.companyId) {
          this.$refs.form.getDetails({ companyId: data.companyId }, (data) => {
            this.formItem = data
            this.areaIds = [this.formItem.proId, this.formItem.cityId, this.formItem.areaId]
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.formItem = this.getFormItem()
          this.loaded = true
        }
      },
      handleSubmit(callback) {
        this.$refs.form.handlerSubmit({}, callback)
      }
    },
    created() {

    },
    components: {  }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
